package trader;

import java.math.BigDecimal;
import java.util.HashMap;

public class Trader {
	
	private String name;
	private BigDecimal cash;
	private HashMap<String, Integer> ores;
	
	public Trader(String name, BigDecimal cash, HashMap<String, Integer> ores) {
		super();
		this.name = name;
		this.cash = cash;
		this.ores = ores;
	}
	
	public void incrementCash(BigDecimal amount) {
		this.cash.add(amount);
	}
	
	public void decrementCash(BigDecimal amount) {
		this.cash.subtract(amount);
	}
	
	public void incrementOre(String oreName, Integer amount) {
		Integer original = 0;
		if (ores.containsKey(oreName)) original = ores.get(oreName);
		ores.put(oreName, original+amount);
	}
	
	public void decrementOre(String oreName, Integer amount) {
		if (ores.containsKey(oreName)) {
			Integer original = ores.get(oreName);
			ores.put(oreName, original-amount);
		}
	}
	
	public Integer getOreAmount(String ore) {
		if (ores.containsKey(ore)) return ores.get(ore);
		else return new Integer(0);
	}

	public String getName() {
		return name;
	}
	
	public BigDecimal getCash() {
		return cash;
	}
	
	public String toString() {
		return "Trader: " + name + ", $" + cash;
	}

}
